<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <div class="div-sch">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="年份" prop="attendYear">
              <el-input
                v-model="queryParams.attendYear"
                placeholder="请输入年份"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="月份" prop="attendMonth">
              <el-input
                v-model="queryParams.attendMonth"
                placeholder="请输入月份"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>
        </div>

        <div class="div-t">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['attend:report:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="reportList" border>
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="年份" align="center" prop="attendYear" />
            <el-table-column label="月份" align="center" prop="attendMonth" />
            <el-table-column label="部门" align="center" prop="deptName" />
            <el-table-column label="出勤" align="center" prop="normal">
              <template slot-scope="scope">
                {{ scope.row.normal == 0 ? "" : scope.row.normal }}
              </template>
            </el-table-column>
            <el-table-column label="迟到" align="center" prop="late">
              <template slot-scope="scope">
                {{ scope.row.late == 0 ? "" : scope.row.late }}
              </template>
            </el-table-column>
            <el-table-column label="早退" align="center" prop="early">
              <template slot-scope="scope">
                {{ scope.row.early == 0 ? "" : scope.row.early }}
              </template>
            </el-table-column>
            <el-table-column label="旷工" align="center" prop="absent">
              <template slot-scope="scope">
                {{ scope.row.absent == 0 ? "" : scope.row.absent }}
              </template>
            </el-table-column>
            <el-table-column label="漏打卡" align="center" prop="missing">
              <template slot-scope="scope">
                {{ scope.row.missing == 0 ? "" : scope.row.missing }}
              </template>
            </el-table-column>
            <el-table-column label="请假" align="center" prop="vacation">
              <template slot-scope="scope">
                {{ scope.row.vacation == 0 ? "" : scope.row.vacation }}
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDetail(scope.row)"
                  v-hasPermi="['attend:report:edit']"
                  >详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  listReport,
  listDeptReport,
  getReport,
  delReport,
  addReport,
  updateReport,
} from "@/api/business/attendReport";

export default {
  name: "Report",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考勤统计表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        attendYear: null,
        attendMonth: null,
        deptId: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考勤统计列表 */
    getList() {
      this.loading = true;
      listDeptReport(this.queryParams).then((response) => {
        this.reportList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考勤统计";
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      const deptId = row.deptId;
      const attendYear = row.attendYear;
      const attendMonth = row.attendMonth;
      this.$router.push(
        "/attend/staff-attend/staff/" +
          deptId +
          "/" +
          attendYear +
          "/" +
          attendMonth
      );
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "attend/report/export",
        {
          ...this.queryParams,
        },
        `report_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped lang="scss">
.app-container {
  .head-container {
    margin-bottom: 10px;
  }
  .tree-container {
    padding: 10px 0;
    background-color: #fff;
  }
}
</style>
